//
//  NewInMechanismCell.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2018/11/20.
//  Copyright © 2018年 HCreater. All rights reserved.
//

#import "NewInMechanismCell.h"

@interface NewInMechanismCell ()

/// viewModle
@property (nonatomic, readwrite, strong) NewInMechanismCellModel *viewModel;

/// IBOutlet
@property (weak, nonatomic) IBOutlet UILabel* nameLabel;
@property (weak, nonatomic) IBOutlet UILabel* contentLabel;
@property (weak, nonatomic) IBOutlet UIImageView* avatarImgView;

@end

@implementation NewInMechanismCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

#pragma mark - bind data
- (void)bindViewModel:(NewInMechanismCellModel *)viewModel
{
    self.viewModel = viewModel;
    
    @weakify(self);
    
    self.nameLabel.text = viewModel.name;
    
//    self.contentLabel.text = viewModel.content;
    
    CGFloat fontSize = 12.0f;
    NSString* string = viewModel.content;
    if (string!=nil && [string isNotBlank])
    {
        NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:string];
        NSUInteger length = [string length];
        //设置字体
        //    UIFont *baseFont = [UIFont systemFontOfSize:fontSize];
        //    [attrString addAttribute:NSFontAttributeName value:baseFont range:NSMakeRange(0, length)];//设置所有的字体
        //    UIFont *boldFont = [UIFont boldSystemFontOfSize:fontSize];
        //    [attrString addAttribute:NSFontAttributeName value:boldFont range:[string rangeOfString:@"Text"]];//设置Text这四个字母的字体为粗体
        //    //设置倾斜，需要导入coreText
        //    UIFont *italicFont = GetVariationOfFontWithTrait(baseFont,
        //                                                     kCTFontTraitItalic);
        //    [attrString addAttribute:NSFontAttributeName value:italicFont
        //                       range:[string rangeOfString:@"Label"]];
        // 设置颜色
        UIColor *firstColor = [UIColor blackColor];
        UIColor* textColor = UIColorHex(#4f4f4f);
        [attrString addAttribute:NSForegroundColorAttributeName
                           value:firstColor
                           range:NSMakeRange(0, 5)];
        [attrString addAttribute:NSForegroundColorAttributeName value:textColor range:NSMakeRange(5, string.length - 5)];
        
        //可以对这些属性设置值
        //字体名称有以下：
        //    label.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:24];
        //    [attrString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Verdana-BoldItalic" size:18] range:[string rangeOfString:@"Label"]];
        //    label.numberOfLines = 2;
//        NSMutableParagraphStyle* style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
//        style.lineSpacing = 4;//增加行高
        //    style.headIndent = 10;//头部缩进，相当于左padding
        //    style.tailIndent = -10;//相当于右padding
        //    style.lineHeightMultiple = 1.5;//行间距是多少倍
        //    style.alignment = NSTextAlignmentLeft;//对齐方式
        //    style.firstLineHeadIndent = 20;//首行头缩进
        //    style.paragraphSpacing = 10;//段落后面的间距
        //    style.paragraphSpacingBefore = 20;//段落之前的间距
//        [attrString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, length)];
        
        //    [attrString addAttribute:NSKernAttributeName value:@2 range:NSMakeRange(0, length)];//字符间距 2pt
        //    [attrString addAttribute:NSStrokeColorAttributeName value:[UIColor blueColor] range:[string rangeOfString:@"is"]];//设置文字描边颜色，需要和NSStrokeWidthAttributeName设置描边宽度，这样就能使文字空心
        //    [attrString addAttribute:NSStrokeWidthAttributeName value:@2 range:[string rangeOfString:@"is"]];//空心字，文字边框描述
        //    [attrString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:[string rangeOfString:@"text"]];//下划线
        //    [attrString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleThick) range:[string rangeOfString:@"label"]];//厚的下划线
        //    [attrString addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:[string rangeOfString:@"things"]];//删除线
        //    [attrString addAttribute:NSStrikethroughColorAttributeName value:[UIColor blueColor] range:[string rangeOfString:@"things"]];//删除线蓝色
        self.contentLabel.attributedText = attrString;
    }
    
    [self.avatarImgView yy_setImageWithURL:[NSURL URLWithString:self.viewModel.avatarImgurl] placeholder:MHImageNamed(@"placeholderLogo")];
    
    
    [[self rac_signalForSelector:@selector(layoutSubviews)] subscribeNext:^(id x)
     {
         @strongify(self);
         
         self.avatarImgView.layer.cornerRadius = self.avatarImgView.frame.size.width/2.0f;
         self.avatarImgView.layer.masksToBounds = YES;
     }];
}

@end
